//
// Created by ASUS on 2023/11/13.
//
struct Node{
	Node*son[2]{};
};

class Trie{
public:
	Node*root;
	Trie(){
		root=new Node();
	}
	void insert(int x){
		Node*cur=root;
		for(int i=30;~i;--i){
			int b=x>>i&1;
			if(!cur->son[b]){
				cur->son[b]=new Node();
			}
			cur=cur->son[b];
		}
	}

	int search(int x) {
		Node* cur = root;
		int ans = 0;
		for (int i = 30; ~i; --i) {
			int b = x >> i & 1;
			if (cur->son[b ^ 1]) {
				ans |= 1 << i;
				cur = cur->son[b ^ 1];
			} else {
				cur = cur->son[b];
			}
		}
		return ans;
	}
};